package org.maxgroundstation.simulation.service.echo;

import org.maxgroundstation.simulation.service.Service;
import org.maxgroundstation.simulation.service.ServiceCommunication;
import org.maxgroundstation.simulation.service.ServiceDataFrame;
import org.maxgroundstation.simulation.service.ServiceUtil;

/**
 * The echo service.
 */
public class EchoService extends Service {

	// Static members
	public static final String SERVICE_ID = ServiceUtil.getServiceID("__echo");
	
	/**
	 * Constructor
	 * @param comm the service communication.
	 */
	public EchoService(ServiceCommunication comm) {
		// Use Service constructor.
		super(comm);
		
		name = "Echo";
		description = "Echos back any message from ground station.  Useful for testing ping time.";
	}
	
	@Override
	public String getID() {
		return SERVICE_ID;
	}

	@Override
	public boolean isDefaultService() {
		return true;
	}

	@Override
	public void handleResponse(ServiceDataFrame dataFrame, int commType) throws Exception {
		// Respond with same data message back to client.
		comm.sendServicePost(commType, getID(), dataFrame.getClientID(), dataFrame.getDataBytes());
	}

	@Override
	public void shutDown() {
		// Do nothing.
	}
	
	@Override
	public boolean isSubscribable() {
		return false;
	}
}